package com.jtjrenren.android.taxi.passenger.core.app.guide;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseActivity;
import com.jtjrenren.android.taxi.passenger.core.main.HomeActivity;
import com.jtjrenren.android.taxi.passenger.core.adapter.GuideVpAdapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnPageChange;

/**
 * Created by Administrator on 2015/12/21.
 */
public class AppGuideActivity extends BaseActivity {
    public static final String EXTRA_ISGOMAINPAGE = "go_mainpage";  //是否要点击最后按钮跳转到主页面,主要用于是不是从关于界面进来展示

    private final int imgs[] = {R.mipmap.def_guide_1, R.mipmap.def_guide_2};

    @BindView(R.id.guide_vp_show)
    ViewPager vp_guide;
    @BindView(R.id.guid_point_1)
    RadioButton rb_1;
    @BindView(R.id.guid_point_2)
    RadioButton rb_2;
    @BindView(R.id.guid_point_3)
    RadioButton rb_3;

    private boolean isJustShow = false;

    @Override
    public int getLayoutId() {
        return R.layout.aty_app_guide;
    }

    @Override
    public void init() {
        if (getIntent().hasExtra(EXTRA_ISGOMAINPAGE)) {
            isJustShow = getIntent().getBooleanExtra(EXTRA_ISGOMAINPAGE, false);
        }

        GuideVpAdapter adapter = new GuideVpAdapter(getViews());
        vp_guide.setAdapter(adapter);
    }

    @OnPageChange(R.id.guide_vp_show)
    void onPageSelected(int position) {
        if (position == 0) {
            rb_1.setChecked(true);
        } else if (position == 1) {
            rb_2.setChecked(true);
        } else if (position == 2) {
            rb_3.setChecked(true);
        }
    }

    private ArrayList<View> getViews() {
        ArrayList<View>  views = new ArrayList<View>();
        View iv;
        for (int i = 0; i < imgs.length; i++) {
            iv = new ImageView(this);
            iv.setBackgroundResource(imgs[i]);
            views.add(iv);
        }
        View lastview = View.inflate(this, R.layout.guide_last_item, null);
        lastview.findViewById(R.id.guide_last_bt_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isJustShow) {
                    finish();
                    return;
                }
                Intent intent = new Intent(AppGuideActivity.this, HomeActivity.class);
                startActivity(intent);
                finish();
            }
        });
        views.add(lastview);
        return views;
    }

}
